home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / UCRASM25.ARJ / STRSETM.ASM < prev    next >
Assembly Source File  |  1991-10-12  |  1KB  |  67 lines

  1. StdGrp        group    stdlib,stddata
  2. stddata        segment    para public 'sldata'
  3. stddata        ends
  4. ;
  5. stdlib        segment    para public 'slcode'
  6.         assume    cs:stdgrp
  7. ;
  8.         extrn    sl_malloc:far
  9. ;
  10. ;
  11. ; strsetm-     Allocates a string containing CX+1 characters and initializes
  12. ;        all but the last byte to the character passed in AL.  Zero
  13. ;        terminates the entire string.
  14. ;
  15. ; inputs:
  16. ;
  17. ;    AL-    Character to copy.
  18. ;    CX-    # of characters in new string.
  19. ;
  20. ; outputs:
  21. ;
  22. ;    es:di-    Points at newly created string (if allocated).
  23. ;
  24. ;    carry=0 if no error creating string.
  25. ;    carry=1 if insufficient memory to allocate storage for string.
  26. ;
  27. ;
  28. ;
  29. ;
  30.         public    sl_strsetm
  31. ;
  32. sl_strsetm    proc    far
  33.         pushf
  34.         push    ax
  35.         push    cx
  36. ;
  37.         cld
  38.                 inc    cx            ;Include zero byte at EOS.
  39.         call    sl_malloc        ;Allocate space for string
  40.         jc    ss2sc            ;Branch if insufficent memory.
  41. ;
  42.         pop    cx            ;Retrieve count.
  43.         push    cx
  44.         push    di            ;Save ptr to free memory
  45.     rep    stosb                ;Fill string with char in AL.
  46.         mov    byte ptr es:[di], 0    ;Zero terminate
  47.         pop    di
  48. ;
  49. ss2cc:        pop    cx
  50.         pop    ax
  51.         popf
  52.                 clc
  53.         ret
  54.  
  55. ss2sc:        pop    cx
  56.         pop    ax
  57.         popf
  58.         stc
  59.         ret
  60. sl_strsetm    endp
  61. ;
  62. ;
  63. ;
  64. ;
  65. stdlib        ends
  66.         end
  67.